//
//  ViewController.m
//  小相册
//
//  Created by li cheng on 16/7/20.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ViewController.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface ViewController ()<UIScrollViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    // 创建一个大的scrollView
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.view addSubview:scrollView];
    // 创建一个装照片的数组
    NSArray *arrayOfAlme = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", nil];
    // 循环把照片添加到scrollView里面
    for (int i = 0; i < arrayOfAlme.count; i++) {
        //创建小的scrollview
        UIScrollView *smallScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(i * WIDTH, 0, WIDTH, HEIGHT)];
        smallScrollView.delegate = self;
        smallScrollView.minimumZoomScale = 0.5;
        smallScrollView.maximumZoomScale = 2;
        UIImageView *imageView = [[UIImageView  alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
        imageView.image = [UIImage imageNamed:arrayOfAlme[i]];
        [smallScrollView addSubview:imageView];
        [scrollView addSubview:smallScrollView];
    }
    // 设置
    scrollView.contentSize = CGSizeMake(WIDTH * arrayOfAlme.count, 0);
    scrollView.pagingEnabled = YES;
    scrollView.bounces = NO;
    scrollView.backgroundColor = [UIColor colorWithRed:1.000 green:0.279 blue:0.248 alpha:1.000];
    
    NSLog(@"-------%@", scrollView.nextResponder);
}
// 必须要写这个方法才能滑动
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return [scrollView.subviews firstObject];
}
// 当滑动结束的时候
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
//    UIScrollView *scrollView = (UIScrollView *)self.nextResponder;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
